package juc.forkJoin;

import java.util.concurrent.ForkJoinPool;

/**
 * @program: check-repetition
 * @description:
 * @author: hjk
 * @create: 2021-07-13 14:14
 **/
public class ForkJoinPoolDemo {

    /**
     * 生成一个计算任务，计算 1+2+3.........+1000
     * @param args
     */
    public static void main(String[] args) {
        //定义任务
        ForkJoinTask taskExample = new ForkJoinTask(1, 1000);
        //定义执行对象
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        //加入任务执行
        java.util.concurrent.ForkJoinTask<Long> result = forkJoinPool.submit(taskExample);
        //输出结果
        try {
            System.out.println(result.get());
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            forkJoinPool.shutdown();
        }
    }
}
